#include <stdio.h>
#include <string.h>
#include <stdlib.h.>
// @brief 字符串的复制，要求地址不一样；不能直接 = 
int main(void)
{
    // 使用栈变量
    char res[1024] = { 0 };
    char *a = "abcdefg";
    printf("====1======= %s ===%p \n", res, res);
    printf("====2=======%s===%p \n", a, a);
    // strlen 不包含\0
    strncpy(res, a, strlen(a));
    printf("====3======= %s ===%p \n", res, res);

    // 使用堆变量实现
    char *b = NULL;
    // +1是为了存储结束符 \0
    b = malloc(strlen(a) + 1);
    if(b == NULL) {
        return  -1;
    }
    printf("====4======= %s ===%p \n", b, b);
    printf("====5======= %d \n", strlen(a));
    // strncpy(b, a, strlen(a));
    strncpy(b, a, strlen(a));
    printf("====6======= %s ===%p \n", b, b);


    if (b != NULL) {
        free(b);
    }
    return 0;
}